package com.coco.user.controller;

import com.coco.user.pojo.TbShippingAddress;
import com.coco.user.service.ShippingAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: coco
 * @author: Mr.Lin
 * @create: 2021-07-21 20:09
 **/
@RestController
@RequestMapping("/shippingAddress")
public class ShippingAddressController {

    @Autowired
    private ShippingAddressService shippingAddressService;
    
    /**
     * 地址列表
     * @return
     */
    @GetMapping("/shippingAddressList")
    public List<TbShippingAddress> shippingAddressList(){
        return shippingAddressService.shippingAddressList();
    }

    /**
     * 查询单条
     * @return
     */
    @GetMapping("/findOne/{id}")
    public TbShippingAddress findOne(@PathVariable("id") Long id){
        return shippingAddressService.findOne(id);
    }

    /**
     * 增加
     * @param shippingAddress
     * @return
     */
    @PostMapping("/add")
    public void add(@RequestBody TbShippingAddress shippingAddress){
        try {
            shippingAddressService.add(shippingAddress);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 修改
     * @param shippingAddress
     * @return
     */
    @PutMapping("/update")
    public void update(@RequestBody TbShippingAddress shippingAddress){
        try {
            shippingAddressService.update(shippingAddress);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 删除
     *
     * @param id
     */
    @DeleteMapping("/deleteById/{id}")
    public void  deleteById(@PathVariable("id") Long id){
        shippingAddressService.deleteById(id);
    }



}

